﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADONETDataServicesExtension.Utils;
using System.Collections;

namespace ADONETDataServicesExtension.Providers
{
    public class ResourceType : FrameworkEncapsulatedType<object>
    {
        internal const string FrameworkTypeName = "System.Data.Services.Providers.ResourceType";

        public ResourceType(object resourceType)
            : base(resourceType)
        {
        }

        public List<ResourceProperty> KeyProperties
        {
            get
            {
                return ReflectionHelper.Convert(ReflectionHelper.GetField<IList>(FrameworkTypeName, "keyProperties", FrameworkObject), frameworkValue => frameworkValue.Cast<object>().Select(kp => new ResourceProperty(kp)).ToList());
            }
        }

        public ResourceProperty TryResolvePropertyName(string propertyName)
        {
            return ReflectionHelper.Convert(ReflectionHelper.InvokeMethod(FrameworkTypeName, "TryResolvePropertyName", FrameworkObject, propertyName), frameworkValue => new ResourceProperty(frameworkValue));
        }

        public string FullName
        {
            get
            {
                return ReflectionHelper.GetProperty<string>(FrameworkTypeName, "FullName", FrameworkObject);
            }
        }

        public Type Type
        {
            get
            {
                return ReflectionHelper.GetProperty<Type>(FrameworkTypeName, "Type", FrameworkObject);
            }
        }

        public Func<object> ConstructorDelegate
        {
            get
            {
                return ReflectionHelper.GetProperty<Func<object>>(FrameworkTypeName, "ConstructorDelegate", FrameworkObject);
            }
        }
    }
}
